<template>
	<view class="container">
		<navigationBar :titleName="'招标详情'" :url="'pagesIndex/detailshare?id='+id" :detailTitle="info.noticeTitle2"></navigationBar>
		
		<view class="content">
			<view class="detail">
				<view class="title" v-html="info.noticeTitle"></view>
				<view class="info">
					<view class="source-date">
						<text class="source">{{ info.noticeType }}</text>
						<text class="date">{{ info.publishTime }}</text>
					</view>
					<view class="read" v-if="info.viewCount">
						<uni-icons type="eye"></uni-icons>
						{{ info.viewCount }}
					</view>
					<view  @tap="favorite()" class="favorite">
						<uni-icons :color="isFav==1?'#19be6b':'#373737'" type="star" size="30"></uni-icons>
						
					</view>
				</view>
				
				<view v-if="bidingTable&&flag" class="setVerticalLayout table">
					<view v-if="bidingTable.totalInvestment" class="setOnlyDisplay tableItem">
						<text class="itemLeft">
							总投资
						</text>
						<text class="itemRight">
							{{bidingTable.totalInvestment}}
						</text>
					</view>
					<view v-if="bidingTable.jiaFang&&flag" class="setOnlyDisplay tableItem">
						<text class="itemLeft">
							建设方
						</text>

						<text v-if='bidingTable.jiaFangId' class="itemRight setcolor setWeight"
							@click="toentEterprise(bidingTable.jiaFangId)">
							{{bidingTable.jiaFang}}
						</text>
						<text v-if='!bidingTable.jiaFangId' class="itemRight ">
							{{bidingTable.jiaFang}}
						</text>
					</view>

					<view v-if="bidingTable.contacts" class="setOnlyDisplay tableItem">
						<text class="itemLeft">
							联系人
						</text>
						<text class="itemRight">
							{{bidingTable.contacts}}
						</text>
					</view>
					<view v-if="bidingTable.contactsPhone" class="setOnlyDisplay tableItem">
						<text class="itemLeft">
							联系电话
						</text>
						<text class="itemRight">
							{{bidingTable.contactsPhone}}
						</text>
					</view>
					<view v-if="bidingTable.openTime" class="setOnlyDisplay tableItem">
						<text class="itemLeft">
							开标时间
						</text>
						<text class="itemRight">
							{{bidingTable.openTime}}
						</text>
					</view>
					<view v-if="bidingTable.proxyOrgan&&flag" class="setOnlyDisplay tableItem">
						<text class="itemLeft">
							招标代理机构
						</text>

						<text v-if='bidingTable.proxyOrganId' class="itemRight setcolor setWeight"
							@click="toentEterprise(bidingTable.proxyOrganId)">
							{{bidingTable.proxyOrgan}}
						</text>
						<text v-if='!bidingTable.proxyOrganId' class="itemRight ">
							{{bidingTable.proxyOrgan}}
						</text>
					</view>
					<view v-if="bidingTable.winningBidder&&flag" class="setOnlyDisplay tableItem">
						<text class="itemLeft">
							{{typeFlag?'第一名':'中标人'}}
						</text>

						<text v-if='bidingTable.winningBidderId' class="itemRight setcolor setWeight"
							@click="toentEterprise(bidingTable.winningBidderId)">
							{{bidingTable.winningBidder}}
						</text>
						<text v-else class="itemRight ">
							{{bidingTable.winningBidder}}
						</text>
					</view>
					<view v-if="bidingTable.bidderMoney" class="setOnlyDisplay tableItem">
						<text class="itemLeft">
							
							{{typeFlag?'报价':'中标价'}}
							
						</text>
						<text class="itemRight">
							{{bidingTable.bidderMoney}}
						</text>
					</view>
					<view v-if="bidingTable.bidder&&flag" class="setOnlyDisplay tableItem">
						<text class="itemLeft">
							招标人
						</text>

						<text v-if='bidingTable.bidderId' class="itemRight setcolor setWeight"
							@click="toentEterprise(bidingTable.bidderId)">
							{{bidingTable.bidder}}
						</text>
						<text v-else class="itemRight ">
							{{bidingTable.bidder}}
						</text>
					</view>
					<view v-if="bidingTable.regulatory" class="setOnlyDisplay tableItem">
						<text class="itemLeft">
							监管部门
						</text>
						<text class="itemRight">
							{{bidingTable.regulatory}}
						</text>
					</view>
				</view>
				<view v-if="bidingTable&&flag" class="setDisplayCenter" style="background-color: #f4f9ff;margin: 40rpx 0 0 0;padding: 20rpx 5rpx;">
					<!-- #85aa82  -->
					<!-- #b1b100  -->
					<u-icon name="info-circle" color="#9d9d00" size="28"></u-icon>
					<text style="color:#9d9d00;">提示：</text>
					<text>以上数据通过人工智能提取，请以正文为准！</text>
				</view>
				<view class="desc">
					<parser :html="info.content"></parser>
				</view>
				<!-- <view class="desc">

					<view v-if="info.projectCode"><text class="desc_title">项目编号： </text><text>{{info.projectCode}}
						</text></view>
					<view v-if="info.createName"><text class="desc_title">发布单位： </text><text>{{info.createName}}</text>
					</view>
					<view v-if="info.expireDate"><text class="desc_title">投标截止： </text><text>{{info.expireDate}}</text>
					</view>
					<view v-if="info.money"><text class="desc_title">工程造价： </text><text>{{info.money}}</text></view>
					<view v-if="info.bidWinner"><text class="desc_title">中标单位： </text><text>{{info.bidWinner}}</text>
					</view>
					<view v-if="info.zbMoney"><text class="desc_title">中标价格： </text><text>{{info.zbMoney}}</text></view>
					<view v-if="info.companyName"><text class="desc_title">业主名称：
						</text><text>{{info.companyName}}</text></view>

				</view> -->
				<view class="declaration" v-if="info.urlPath">
					<!-- #ifdef APP-PLUS || H5 -->
					<!-- <view class="button" @click="openUrl(info.urlPath)">查看官网原文</view> -->
					<!-- #endif -->

					<!-- <text @tap="copyText(info.urlPath)">点此可查看官网原文链接。</text> -->
					<!-- #ifdef MP -->
					<!-- <uni-link :href="info.urlPath" showUnderLine="false" color="#0000ff">查看官网原文</uni-link> -->

					<!-- #endif -->

					<!-- <web-view src="info.urlPath" fullscreen="false"></web-view> -->
				</view>

				<view class="declaration" v-if="info.bidFilePath">

					<!-- <text @tap="copyText(info.urlPath)">点此可查看官网原文链接。</text> -->
					<view class="button" @click="openPdf(info.bidFilePath)">打开附件</view>
				</view>

				<view class="declaration">
					<view class="button" @click="sendEmail">免费发送到邮箱</view>
				</view>
				<view>
					<!-- <text v-if="info.noticeContent"  v-html="info.noticeContent" ></text> -->
					<!-- 不需要引入，可直接使用 -->
					<mp-html v-if="info.noticeContent" :content="info.noticeContent" />
				</view>
			</view>
			<view class="comment" v-if="false">
				<view class="title">
					<text>全部评论</text>
					<text class="count" v-if="comments.count > 0">({{ comments.count }})</text>
				</view>
				<view class="item" v-for="(item, index) in comments.list" :key="index">
					<view class="avatar">
						<image :src="item.avatar_url"></image>
					</view>
					<view class="comment-info">
						<view class="nickname-like">
							<view class="nickname">{{ item.userName }}</view>
							<view class="like">
								<!-- <image @tap="commentLike(item.id, index)" v-show="!item.isDigg"
									src="/static/images/icon_like_01.png"></image>
								<image @tap="commentLike(item.id, index)" v-show="item.isDigg"
									src="/static/images/icon_like_01_hover.png"></image> -->
								<uni-icons @tap="commentLike(item.id, index)" :color="item.isDigg?'#19be6b':'#373737'" type="hand-up" size="30"></uni-icons>
														
								<view class="like-count">{{ item.diggCount||'' }}</view>
							</view>
						</view>
						<view class="comment-desc" hover-class="none">{{ item.content }}</view>
						<view class="date-reply">
							<view class="date" hover-class="none">{{ item.createTime }}</view>
							<!-- <navigator class="reply" :url="'commentDetail?operate=reply' + '&id=' + item.id">回复TA</navigator> -->
						</view>
						<view class="reply-count" v-if="item.replyCount > 0" :url="'commentDetail?id=' + item.id"
							hover-class="none">
							全部{{ item.replyCount }}条回复 >
						</view>
					</view>
				</view>
				<loading v-if="hasMoreData"></loading>
				<view class="no-comment" v-if="comments.count == 0">暂无评论，快来抢占沙发吧~</view>
			</view>
			<view class="float-empty"></view>
			<!-- 2023年6月19日 因app市场审核原因,暂时删除评论模块 -->
			
			<view class="comment-bar"  v-if="false" v-show="!showAddComment && showCommenBar">
				<view class="input" @tap="initAddComment(true)"><text>发表评论</text></view>
				<view class="operate">
					<view class="info" hover-class="none">
						<uni-icons type="chatboxes" size="30"></uni-icons>
						<text class="count" v-if="comments.count > 0">{{ comments.count }}</text>
					</view>
					<view  @tap="like()" class="like">
							<uni-icons :color="isDigg==1?'#19be6b':'#373737'" type="hand-up" size="30"></uni-icons>
						
					 </view>
					<view  @tap="favorite()" class="favorite">
						<uni-icons :color="isFav==1?'#19be6b':'#373737'" type="star" size="30"></uni-icons>
						
					</view>

					<view class="">
						<!-- #ifdef MP-WEIXIN -->
						<button open-type="share" class="share" @tap="share">
							
							<uni-icons type="redo" size="30"></uni-icons>
							
						</button>
						<!-- #endif -->

						<!-- #ifdef APP-PLUS  -->
						<share :color="'#565656'" :url="'pagesIndex/detailshare?id='+id" :detailTitle="info.noticeTitle2"></share>
						<!-- #endif -->
					</view>
				</view>
			</view>

			<view class="bg-masker" v-if="showAddComment" @tap="initAddComment(false)"></view>
			<view class="add-comment" v-if="showAddComment">
				<view class="info">
					<view class="input">
						<textarea :show-confirm-bar="false" :cursor-spacing="20" ref="commentContent" :maxlength="200"
							:auto-height="true" :fixed="true" :focus="showAddComment" v-model.trim="commentContent"
							placeholder-class="input-bg"
							:placeholder="replyCommentId > 0 ? '回复 ' + replyNickname + '：' : '发表评论'" />
					</view>
					<view class="add">
						<button class="mini-btn" type="primary" size="mini"
							@click="addCommentOrReply()">{{ replyCommentId > 0 ? '回复' : '发表' }}</button>
					</view>
				</view>
			</view>

			
		</view>
		<pageLoading v-if="showPageLoading"></pageLoading>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import together from '@/common/together.js';
	// import parser from '@/components/parser/parser.vue';
	import pageLoading from '@/components/loading/pageLoading.vue';
	import iconfont from '@/components/iconfont/iconfont.vue';
	import loading from '@/components/loading/loading.vue';
	import util from '@/common/util.js';
	import wechatMP from '@/common/sdk/wechatMP.js';
	import validator from '@/common/validator';
	import parser from './parser/index.vue';
	export default {
		components: {
			parser,
			pageLoading,
			loading,
			iconfont
		},
		data() {
			return {
				// 标题中是否包涵中标公示 
				typeFlag:false,
				isDigg:null,
				isFav:null,
				flag: null,
				id: 0,
				info: {},
				showAddComment: false,
				showCommenBar: true,
				addCommentFocus: false,
				commentContent: '',
				replyCommentId: 0,
				replyNickname: '',
				page_index: 1,
				page_size: 10,
				hasMoreData: false,
				showPageLoading: true,
				currentUrl: '',
				shareUrl: '',
				showShareTip: false,
				showH5Share: false,
				showBrowserShareTip: false,
				//评论数据
				comments: {},
				// 标红关键字
				keyword: null,
				//存储招标信息
				bidingTable: null
				// bidingTable: {
				// 	bidderId:'',
				// 	proxyOrganId:'',
				// 	winningBidderId:'',
				// 	jiaFangId:''
				// }
			};
		},
		onShow(e) {
			this.$initPageTitle(); //初始化页面标题
			if (this.page_index > 1) {
				this.page_index = 1;
				this.getData();
			}

			/*来源是登录时更新*/
			let source = uni.getStorageSync('source');
			if (source == 'login') {
				uni.removeStorageSync('source');
				this.loadData();
			}


		},
		onLoad(e) {
			// 拿取关键字
			if (e.keyword) {
				this.keyword = e.keyword

			}
			if (e.id) {
				this.id = e.id;

				if (!uni.getStorageSync('isLogin')) {
					uni.setStorageSync('LoginPage', '/pagesIndex/detail?id=' + this.id);
				}


				this.getfindZbProperty()
			}else{
				uni.showToast({
					title:'内容不存在'
				})
				
				return 
			}
			// #ifdef H5
			this.currentUrl = encodeURIComponent(window.location.href);
			// #endif
			this.getData();

			this.viewCount();

		},
		onPullDownRefresh() {
			
			this.page_index = 1;
			this.getData();
			
		},
		onReachBottom(e) {
			if (this.hasMoreData) {
				this.getComment();
			}
		},

		beforeDestroy() {
			// 更新首页点赞收藏
			
			uni.$emit('listUpdata')
			uni.$emit('listUpdata2')
		},
		methods: {

			// 跳转至企业详情
			toentEterprise(id) {

				uni.navigateTo({
					url: `/pagesFind/detailenterprise/detailenterprise?companyCid=${id}`
				})
			},

			getfindCompanyName(item, num) {
				// 查询该单位是否存在
				this.$app.request({
					url: this.$baseApp.api.check.findOnlyCompanyName,
					data: {
						name: item
					},
					method: 'GET',
					dataType: 'json',
					success: res => {

						if (res.code == 200) {
							if (res.data.content.length > 0) {
								// 跳转至详情
								let id = res.data.content[0].companyCid

								if (num == 1) {
									this.bidingTable.jiaFangId = id
								}
								if (num == 2) {
									this.bidingTable.bidderId = id
								}
								if (num == 3) {
									this.bidingTable.winningBidderId = id
								}
								if (num == 4) {
									this.bidingTable.proxyOrganId = id

								}

							}
						}
						this.flag = true
						// console.log("this.bidingTable",this.bidingTable)
					}
				});
			},
			// 查找该中标信息详情
			getfindZbProperty() {
				let url = this.$baseApp.api.check.findZbProperty + "?id=" + this.id;

				// let url = this.$baseApp.api.check.findZbProperty + "?id=" + '1_33_0020010053d7a1a41-6d45-4ad6-b28b-decd4b11ab2e_001';
				this.$http.get(url).then(res => {

					if (res.code == '200') {

						if (res.data) {

							this.bidingTable = res.data



							// 获取四个单位的id
							if (this.bidingTable.jiaFang) {
								this.getfindCompanyName(this.bidingTable.jiaFang, 1)

							}
							if (this.bidingTable.bidder) {
								this.getfindCompanyName(this.bidingTable.bidder, 2)

							}
							if (this.bidingTable.winningBidder) {
								this.getfindCompanyName(this.bidingTable.winningBidder, 3)

							}
							if (this.bidingTable.proxyOrgan) {
								this.getfindCompanyName(this.bidingTable.proxyOrgan, 4)

							}

						}
					}

				})
			},

			//发送到邮箱
			sendEmail() {
				uni.showLoading({
					title: '请稍候...'
				})
				let url = this.$baseApp.api.zhaobiao.sendEmail + "/" + this.id;
				let data = {}
				// 查询用户是否已填写好邮箱地址
				this.$http.post(url, data).then(res => {
					if (res.code == '200') {
						this.$alert('成功发送到: ' + res.data);
						uni.hideLoading()
					}
				}, err => {

					console.info(err);
					if (err.code == '509') {
						this.$alert('请先填写邮箱');
						setTimeout(() => {
							// 判断用户是否已绑定手机号，未绑定手机号，跳转至手机号绑定页面
							let wxcathePhone = together.isBindPhone()
							// console.log("wxcathePhone", wxcathePhone)
							// 进入绑定页面  通过传参判断  1 绑定手机  2绑定邮箱
							if (!wxcathePhone) {
								uni.navigateTo({
									url: '/pagesUser/bindMailbox?status=1'
								})
							} else {
								uni.navigateTo({
									url: '/pagesUser/bindMailbox?status=2'
								})
							}
							// uni.navigateTo({
							// 	url:'/pagesUser/profile'
							// })
						}, 1000)
					}
				})
			},
			/*加载数据*/
			loadData() {
				this.getData();
			},

			/*获取文章详情*/
			getData() {
			
				let data = {
					id: this.id
				}

				this.$app.request({
					url: this.$baseApp.api.zhaobiao.detail,
					data: data,
					method: 'GET',
					dataType: 'json',
					success: res => {
						if (res.code == 200) {
							// 用户是否点赞收藏过
							// 拿取用户保存在本地的点赞和收藏数据
							let localisFav = uni.getStorageSync('localisFav')
							let localDigg = uni.getStorageSync('localDigg')
							this.info = res.data;

							if (localisFav) {
								localisFav.forEach(fav => {
									if (fav == this.info.id)
										this.isFav =1
								})
							}
							if (localDigg) {
								localDigg.forEach(digg => {
									if (digg == this.info.id)
										this.isDigg = 1
								})
							}
							
							// 搜索当前标题里面有没有中标公示这几个字
							let typeFlag=this.info.noticeTitle.indexOf('中标公示')
							let typeFlag2=this.info.noticeType.indexOf('候选人')
							let typeFlag3=this.info.noticeTitle.indexOf('结果公示')
							let typeFlag4=this.info.noticeTitle.indexOf('中标候选人')
							if(typeFlag>-1||typeFlag2>-1||typeFlag3>-1||typeFlag4>-1){
								// 中标公示存在
								this.typeFlag=true
							}
							
							this.info.noticeTitle2=this.info.noticeTitle
							if (this.keyword) {
								// 
								this.info.noticeTitle = validator.joinStr(this.info.noticeTitle, this.keyword)
								this.info.noticeContent = validator.joinStr(this.info.noticeContent, this
									.keyword)
							}


							//设置表头
							uni.setNavigationBarTitle({
								title: (this.info.areaName || '') + ' ' + this.info.noticeType
							});
							this.$initPageTitle();
							this.showPageLoading = false;

							this.initMPShare(); //公众号分享

							//加载评论
							this.getComment();

							if (this.info.bidFilePath) {
								//this.openPdf(this.info.bidFilePath)
							}

						} else if (res.code == 440) {
							uni.$emit('bindVip')
							// 保存当前页面id
							uni.setStorageSync('limitId', {
								type: 'zhaobiao',
								id: this.id
							});
							// 跳转至充值页面
							together.memberTip()

						} else {
							// this.$alert(res.msg);
							uni.navigateBack()

						}
					},

					complete: res => {
						// if(res.data.code==440){
						// 	// 保存当前页面id
						// 	uni.setStorageSync('limitId', {
						// 		type:'zhaobiao',
						// 		id:this.id
						// 	});
						// 	// 跳转至充值页面
						// 	together.memberTip()

						// }
						// console.log('res=============', res)
					}
				});

			},

			openUrl(url) {
				uni.navigateTo({
					url: './detail_url?url=\"' + url + '\"'
				})
			},

			openPdf(url) {

				uni.showLoading({
					title: '附件打开中...'
				})
				// #ifdef MP
				let myurl = this.$baseApp.api.zhaobiao.openPdfFile + "?url=" + url
				// console.info(myurl)
				uni.downloadFile({
					url: myurl,
					success: function(res) {
						var filePath = res.tempFilePath;
						// console.info("临时文件保存路径:" + filePath)
						uni.openDocument({
							filePath: filePath,
							fileType: 'pdf',
							showMenu: true,
							success: function(res) {
								// console.log('打开文档成功');
								uni.hideLoading()
							},
							fail(err) {
								console.log('打开失败' + err)
							}
						});
					}
				});


				// #endif


				// #ifdef APP-PLUS || H5
				uni.downloadFile({
					url: url,
					success: function(res) {
						var filePath = res.tempFilePath;
						console.info("临时文件保存路径:" + filePath)
						uni.openDocument({
							filePath: filePath,
							fileType: 'pdf',
							showMenu: true,
							success: function(res) {
								console.log('打开文档成功');
								uni.hideLoading()
							},
							fail(err) {
								console.log('打开失败' + err)
							}
						});
					}
				});
				// #endif


			},

			/*浏览+1*/
			viewCount() {
				this.userAction(this.id, 'view')
			},
			//浏览,收藏,点赞
			userAction(id, type) {
				let url = this.$baseApp.api.zhaobiao.favCount;
				let url_diggCount = this.$baseApp.api.zhaobiao.diggCount;
				let url_viewCount = this.$baseApp.api.zhaobiao.viewCount;
				if (type == 'digg') {
					url = url_diggCount;

				} else if (type == 'view') {
					url = url_viewCount;

				}

				//console.info('=============='+url)
				this.getUserAction(url,id);

			},
			getUserAction(url,id) {
				this.$http.post(url + "/" + id).then(res => {


					if (res.code == '200') {

						if (type == 'digg') {
							uni.showToast({
								title: '点赞成功'
							})
							this.info.diggCount = (this.info.diggCount || 0) + 1
							// this.info['isDigg'] = 1;
							// console.info(this.info.isDigg)
						} else if (type == 'fav') {
							uni.showToast({
								title: '收藏成功'
							})
							this.info.favCount = (this.info.favCount || 0) + 1
							this.info['isFav'] = 1;

						} else if (type == 'view') {

							this.info.viewCount = (this.info.viewCount || 0) + 1
							this.info['isView'] = true;
						}

					}
				});
			},


			/*评论点赞*/
			commentLike(comment_id, index) {
				this.$app.request({
					url: this.$baseApp.api.zhaobiao.addCommentDigg,
					data: {
						id: comment_id
					},
					method: 'POST',
					dataType: 'json',
					success: res => {
						if (res.code == 200) {
							if (this.comments.list[index].isDigg) {
								this.comments.list[index].isDigg = false;
								this.comments.list[index].diggCount -= 1;
								this.deleteDiggCount(comment_id)
							} else {
								this.comments.list[index].isDigg = true;
								this.comments.list[index].diggCount += 1;
							}
							let msg = this.comments.list[index].isDigg ? '点赞成功' : '已取消点赞';
							this.$alert(msg);
						} else {
							this.$alert(res.msg);
						}
					}
				});
			},
			/*点赞*/
			like(info) {
				let localDigg = uni.getStorageSync('localDigg')
				// 用户取消点赞
				if (this.isDigg==1) {
					this.isDigg = 0
					// 移除该id
					localDigg = localDigg.filter(res => {
						// console.log("res",res)
						return res != this.id
					})
					this.deleteFav(this.id)
				} else {
					// 用户点赞
					if (!localDigg) {
						localDigg = []
					}
					localDigg.push(this.id)
					this.isDigg=1
					this.userAction(this.id, 'digg');
				}
					console.log('this.isDigg',this.isDigg)
				console.log('localDigg',localDigg)
				uni.setStorageSync('localDigg', localDigg);
			},
			/*收藏*/
			favorite() {
				// 保存用户点赞的id至本地
				let localisFav = uni.getStorageSync('localisFav')
				// 用户取消收藏
				if (this.isFav==1) {
					this.isFav = 0
					// 移除该id
					localisFav = localisFav.filter(res => {
						// console.log("res",res)
						return res != this.id
					})
					this.deleteDiggCount(this.id)
				} else {
					// 用户收藏
					if (!localisFav) {
						localisFav = []
					}
					localisFav.push(this.id)
					this.isFav = 1
					this.userAction(this.id, 'fav');
				}
				uni.setStorageSync('localisFav', localisFav);
				console.log('localisFav',localisFav)
			},
			// 取消喜欢
			deleteDiggCount(id) {
				// console.log('-------------------')
				let url = this.$baseApp.api.zhaobiao.deleteDiggCount;
				this.$http.post(url + "/" + id).then(res => {});
			},
			//删除收藏
			deleteFav(id) {

				let url = this.$baseApp.api.zhaobiao.deleteFavCount;
				this.$http.post(url + "/" + id).then(res => {});

			},
			/*初始化添加评论*/
			initAddComment(status) {
				if (status) {
					this.$app.initLogin();
				}
				this.showAddComment = status;
				this.commentContent = '';
				if (this.replyCommentId > 0) {
					this.replyCommentId = 0;
					this.replyNickname = '';
				}
				setTimeout(() => {
					this.addCommentFocus = status;
				}, 200);
			},

			/*添加评论或回复*/
			addCommentOrReply() {
				if (this.commentContent == '') {
					this.$alert('评论内容不能为空');
					return;
				}
				if (this.replyCommentId > 0) {
					this.addReply();
				} else {
					this.addComment();
				}
			},

			/*添加评论*/
			addComment() {
				/* this.$app.request({
					url: this.$api.article.addComment,
					data: {
						article_id: this.id,
						content: this.commentContent,
						page_size: this.page_size
					},
					method: 'POST',
					dataType: 'json',
					success: res => {
						if (res.code == 0) {
							this.comments = res.data;
							this.showAddComment = false;
							this.commentContent = '';
							this.$alert('评论成功');
						} else {
							this.$alert(res.msg);
						}
					}
				}); */
				let url = this.$baseApp.api.zhaobiao.addComment;
				let data = {
					busId: this.info.id, //不是主键是自己定义的id
					content: this.commentContent
				}
				this.$http.post(url, data).then(res => {
					if (res.code == 200) {
						this.$alert('评论成功');

						this.page_index = 1;
						//重新加载数据
						this.getComment()
					}
				})

			},

			/*初始化回复*/
			initAddReply(comment_id, nickname) {
				this.initAddComment(true);
				this.replyCommentId = comment_id;
				this.replyNickname = nickname;
			},

			/*添加回复*/
			addReply() {
				if (this.commentContent == '') {
					this.$alert('回复内容不能为空');
					return;
				}
				this.$app.request({
					url: this.$api.article.addReply,
					data: {
						comment_id: this.replyCommentId,
						content: this.commentContent,
						page_size: this.page_size
					},
					method: 'POST',
					dataType: 'json',
					success: res => {
						if (res.code == 0) {
							this.comments = res.data;
							this.showAddComment = false;
							this.replyCommentId = 0;
							this.replyNickname = '';
							this.commentContent = '';
							this.$alert('评论成功');
						} else {
							this.$alert(res.msg);
						}
					}
				});
			},

			/*获取评论*/
			getComment() {
				/* this.$app.request({
					url: this.$api.article.comment,
					data: {
						article_id: this.id,
						page_index: this.page_index,
						page_size: this.page_size
					},
					method: 'POST',
					dataType: 'json',
					success: res => {
						if (res.code == 0) {
							console.log(this.comments);
							this.comments.list = this.comments.list.concat(res.data.list);
							this.comments.count = res.data.count;
							if (res.data.page > this.page_index) {
								this.hasMoreData = true;
							} else {
								this.hasMoreData = false;
							}
							this.page_index += 1;
						} else {
							this.$alert(res.msg);
						}
					},
					complete: res => {
						uni.stopPullDownRefresh();
						uni.hideLoading();
					}
				}); */

				//获取评论数据
				let url = this.$baseApp.api.zhaobiao.comment;
				// console.info(url)
				let data = {
					busId: this.info.id,
					type: 'comment',
					page: this.page_index,
					pageSize: this.page_size
				}
				this.$http.get(url, data).then(res => {
					if (res.code == 200) {
						this.comments = {
							list: [],
							count: 0
						}
						//this.comments = res.data.content ;
						this.comments.list = this.comments.list.concat(res.data.content);
						// console.info(this.comments.list)
						this.comments.count = res.data.totalElements;
						if (res.data.totalPages > this.page_index) {
							this.hasMoreData = true;
						} else {
							this.hasMoreData = false;
						}
						this.page_index += 1;

					} else {
						this.$alert(res.msg);
					}
				})

			},

			/*打开外部链接*/
			openLink(url) {
				// console.log(url);
				window.location.href = url;
			},

			/*关闭H5分享*/
			closeH5Share() {
				this.showH5Share = false;
			},

			/*关闭微信分享提示*/
			closeShareTip() {
				this.showShareTip = false;
			},
			/*显示浏览器分享提示*/
			showBrowserShareTips() {
				this.showH5Share = false;
				this.showBrowserShareTip = true;
			},
			/*关闭浏览器分享提示*/
			closeBrowserShareTip() {
				this.showBrowserShareTip = false;
			},

			/*分享*/
			share() {
				// #ifdef H5
				if (util.isWechatOrQQ()) {
					this.showShareTip = true;
				} else {
					this.showH5Share = true;
				}
				// #endif

				// console.log('share');

				// #ifdef MP
				// uni.showShareMenu();
				// #endif
			},

			/*初始化公众号分享*/
			initMPShare() {
				// #ifdef H5
				let domain = location.href.split('/pages/')[0];
				/*分享链接*/
				let link = domain + '/pagesIndex/detail?id=' + this.info.id;
				if (this.$app.isWechat()) {
					/*初始化分享*/
					wechatMP.initShare(this, {
						title: this.info.title,
						desc: '',
						link: link,
						imgUrl: this.info.photo_url
					});
				} else {
					this.shareUrl = link;
				}
				// #endif
			},



			/*复制*/
			copyText(text) {
				uni.setClipboardData({
					data: text,
					success: res => {
						this.$alert('原文链接已复制', 'success');
					}
				});
			}
		}
	};
</script>

<style scoped lang="scss">
	.detail {
		padding: 40rpx 32rpx;
		background: #fff;

		.table {
			width: 100%;
			background-color: #e5fdda;
			line-height: 100rpx;
			margin-top: 50rpx;

			view: nth-child(2n) {
				background-color: #b3e19d;
				// background-color:#3ed16c ;
			}

			view:nth-child(2n-1) {
				background-color: #cef5bc;
				// background-color:#00aa8f ;
				// color: #fff;
			}

			.tableItem {
				width: 100%;
				text-align: center;

				.itemLeft {
					width: 30%;

				}

				.itemRight {
					width: 70%;
				}
			}
		}

		.title {
			font-size: 44rpx;
			color: #262626;
			line-height: 70rpx;
			font-weight: bold;
		}

		.info {
			margin-top: 32rpx;
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			align-items: center;

			.source-date {
				.source {
					color: #666;
				}

				.date {
					color: #999;
					margin-left: 24rpx;
				}
			}

			.read {
				color: #999;
			}
		}

		.desc {
			margin-top: 56rpx;
			overflow: hidden;
			color: #262626;

			.wxParse {
				color: #262626;
			}

			view {
				margin-bottom: 20rpx;
			}

			.desc_title {
				// background-image: linear-gradient(to right, #00aa8f, #00aa00);
				padding: 4rpx;
				border-radius: 0 10rpx 10rpx 0;
				margin-right: 10rpx;

				border-bottom: 1px solid #ccc;

			}
		}
	}

	.comment {
		padding: 20rpx 32rpx 0;
		background: #fff;

		.title {
			display: flex;
			align-items: center;
			font-size: 36rpx;
			color: #262626;
			font-weight: bold;
			border-bottom: 1rpx solid #eee;

			text {
				padding-bottom: 20rpx;
				line-height: normal;
			}

			.count {
				padding-bottom: 20rpx;
				font-size: 30rpx;
				color: #999;
				margin-left: 10rpx;
				line-height: normal;
			}
		}

		.item {
			display: flex;
			justify-content: space-between;
			padding: 30rpx 0 20rpx;
			border-bottom: 1rpx solid #eee;

			&:last-child {
				border-bottom: 0;
			}

			.avatar {
				flex-grow: 0;
				flex-shrink: 0;
				margin-right: 20rpx;

				image {
					width: 45rpx;
					height: 45rpx;
					border-radius: 50%;
				}
			}

			.comment-info {
				flex-grow: 1;
				flex-shrink: 1;

				.nickname-like {
					display: flex;
					justify-content: space-between;

					.nickname {
						font-size: 32rpx;
						color: #444;
						font-weight: bold;
					}

					.like {
						display: flex;
						align-items: center;

						image {
							width: 32rpx;
							height: 32rpx;
							margin-right: 14rpx;
						}

						.like-count {
							color: #999;
							font-size: 30rpx;
						}
					}
				}

				.comment-desc {
					color: #444;
					font-size: 32rpx;
					line-height: 1.6;
					margin-top: 15rpx;
				}

				.reply-count {
					background: #f2f2f2;
					padding: 8rpx 20rpx;
					font-size: 30rpx;
					color: #999;
					margin: 20rpx 0 24rpx;
				}

				.date-reply {
					display: flex;
					justify-content: space-between;
					align-items: center;

					.date {
						display: flex;
						align-items: center;
						color: #b4b4b4;
						font-size: 28rpx;
						margin-right: 20rpx;
						margin-top: 4rpx;
					}

					.reply {
						flex-grow: 0;
						flex-shrink: 0;
						font-size: 28rpx;
						color: #999;
					}
				}
			}
		}

		.no-comment {
			padding: 40rpx 0;
			color: #999;
			font-size: 30rpx;
		}
	}

	.comment-bar {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 120rpx;
		background-color: #ffffff;
		box-shadow: 0 1px 1px 1px rgba(0, 0, 0, 0.3);
		display: flex;
		flex-direction: row;

		.input {
			flex-grow: 0;
			flex-shrink: 0;
			margin: 20rpx 10rpx 20rpx 20rpx;
			display: flex;
			align-items: center;
			background: #f2f2f2;
			width: 420rpx;
			border-radius: 40rpx 0rpx 0 40rpx;

			text {
				font-size: 32rpx;
				color: #aaa;
				margin-left: 38rpx;
			}
		}

		.operate {
			width: 100%;
			flex-grow: 1;
			flex-shrink: 1;
			display: flex;
			justify-content: space-around;
			align-items: center;
			margin-right: 10rpx;

			view,
			navigator {
				display: flex;
				justify-content: space-around;
				align-items: center;
				width: 25%;

				image {
					width: 45rpx;
					height: 45rpx;
				}
			}

			.info,
			.like {
				position: relative;

				.count {
					position: absolute;
					top: -15rpx;
					right: -4rpx;
					background-image: linear-gradient(140deg, #bee7e9 9%, #8cc7b5 75%);
					display: flex;
					align-items: center;
					border-radius: 50rpx;
					padding: 0 10rpx;
					font-size: 22rpx;
					color: #fff;
					height: 30rpx;
					line-height: 30rpx;
				}
			}

			.share {
				display: flex;
				justify-content: space-around;
				padding: 0;
				background: transparent;

				image {
					width: 45rpx;
					height: 45rpx;
					border: 0;
				}

				&:after {
					display: none;
				}
			}
		}
	}

	.float-empty {
		height: 120rpx;
		width: 100%;
		display: block;
		background: #fff;
	}

	.add-comment {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		background-color: #ffffff;
		z-index: 9999;

		.info {
			display: flex;
			flex-direction: row;
			padding: 20rpx 20rpx 20rpx 20rpx;

			.input {
				flex-grow: 1;
				flex-shrink: 1;
				display: flex;
				align-items: center;
				background: #f2f2f2;
				border-radius: 40rpx 40rpx 0 40rpx;
				padding: 20rpx 32rpx 20rpx;
				line-height: normal;

				textarea {
					//padding: 10rpx 0;
					width: 100%;
					font-size: 32rpx;
					line-height: 42rpx;
					background: #f2f2f2;
				}
			}

			.add {
				flex-grow: 0;
				flex-shrink: 0;
				width: 150rpx;
				display: flex;
				align-items: center;
				margin-left: 10rpx;
			}

			.cancel {
				position: absolute;
				right: 10rpx;
				top: 2rpx;

				/deep/.icon {
					font-size: 40rpx;
					color: #ccc;
				}
			}
		}
	}

	.h5-share {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		background-color: #ffffff;
		border-top: 1rpx solid #ddd;
		padding-top: 20rpx;
		padding-bottom: 20rpx;

		.title {
			font-size: 30rpx;
			text-align: center;
			height: 50rpx;
		}

		.share-icon {
			display: flex;
			flex-direction: row;
			justify-content: space-around;

			view {
				flex-grow: 0;
				flex-shrink: 0;
				text-align: center;

				image {
					margin-top: 35rpx;
					width: 80rpx;
					height: 80rpx;
				}

				text {
					display: block;
				}
			}
		}

		.share-btn {
			margin: 30rpx 30rpx 15rpx;
			border: 1rpx solid #8cc7b5;
			background: #8cc7b5;
			border-radius: 15rpx;
			font-size: 32rpx;
			text-align: center;
			padding: 12rpx 0;
			color: #fff;
		}
	}

	.share-maske {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		background: rgba(0, 0, 0, 0.6);
		z-index: 99999;

		.share-tip {
			position: absolute;
			top: 100rpx;
			left: 0;
			text-align: center;

			.share-tip-info {
				height: 240rpx;
			}

			.share-tip-btn {
				margin-top: 400rpx;
				height: 82rpx;
			}
		}

		.share-browser-tip {
			top: 300rpx;

			.share-tip-info {
				height: 240rpx;
			}

			.share-tip-btn {
				margin-top: 200rpx;
			}
		}
	}

	.declaration {
		margin: 50rpx 0;
		font-size: 34rpx;
		color: #999;
	}
</style>
